import Action from '../actions/types'

export interface address {
    id: number,
    username: string,
    userPhone: string,
    addressFull: string
}

interface coupon {
    id: number,
    name: string,
    discount: number,
}

export interface buySku {
    num: number,
    skuId: number,
    skuFullName: string,
    skuPrice: number,
    productName: string,
}

export interface StateType {
    selectedAddress: null | address,
    selectedCoupon: null | coupon,
    buySkuList: buySku[],
    remark: string,
}

const initialState: StateType = {
    selectedAddress: null,
    selectedCoupon: null,
    buySkuList: [],
    remark: ''
};

const handle: Record<string, (state: StateType, action: Action) => StateType> = {
    checkoutOrder: function (state, action) {
        return {...state, buySkuList: action.payload};
    },
    selectedAddressSave: function (state, action) {
        return {...state, selectedAddress: action.payload};
    },
    selectedCouponSave: function (state, action) {
        return {...state, selectedCoupon: action.payload};
    },
    remarkSave: function (state, action) {
        return {...state, remark: action.payload};
    }
};
export default {initialState, handle}


